class Admins::TopNewsController < ApplicationController
  before_action :set_top_news, only: [:show, :edit, :update, :destroy]

  # GET /top_news
  # GET /top_news.json
  def index
    @top_news = TopNews.all
  end

  # GET /top_news/1
  # GET /top_news/1.json
  def show
  end

  # GET /top_news/new
  def new
    @top_news = TopNews.new
  end

  # GET /top_news/1/edit
  def edit
  end

  # POST /top_news
  # POST /top_news.json
  def create
    @top_news = TopNews.new(top_news_params)

    respond_to do |format|
      if @top_news.save
        format.html { redirect_to [:admins, @top_news], notice: '首页大图创建成功' }
        format.json { render :show, status: :created, location: @top_news }
      else
        format.html { render :new }
        format.json { render json: @top_news.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /top_news/1
  # PATCH/PUT /top_news/1.json
  def update
    respond_to do |format|
      if @top_news.update_attributes(top_news_params)
        format.html { redirect_to [:admins, @top_news], notice: '首页大图更新成功' }
        format.json { render :show, status: :ok, location: @top_news }
      else
        format.html { render :edit }
        format.json { render json: @top_news.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /top_news/1
  # DELETE /top_news/1.json
  def destroy
    @top_news.destroy
    respond_to do |format|
      format.html { redirect_to admins_top_news_index_url, notice: '首页大图删除成功' }
      format.json { head :no_content }
    end
  end

  private
  # Use callbacks to share common setup or constraints between actions.
  def set_top_news
    @top_news = TopNews.find(params[:id])
  end

  # Never trust parameters from the scary internet, only allow the white list through.
  def top_news_params
    params.require(:top_news).permit(:title, :content, :link_url, :first_image, :second_image, :third_image, :fourth_image, :fifth_image, :status)
  end
  
end
